package edu.ccut.titan.tag.report.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import edu.ccut.titan.tag.report.design.CellInfo;
import edu.ccut.titan.tag.report.design.ColumnGroupInfo;
import edu.ccut.titan.tag.report.design.CrosstabInfo;
import edu.ccut.titan.tag.report.design.MeasureInfo;
import edu.ccut.titan.tag.report.design.NoDataCellInfo;
import edu.ccut.titan.tag.report.design.RowGroupInfo;

public class TitanCrosstabTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	private String header;
	private CrosstabInfo crosstabInfo;
	private TitanReportTag reportTag;

	@Override
	public int doStartTag() throws JspException {
		crosstabInfo = new CrosstabInfo();
		reportTag = (TitanReportTag) this.getParent();
		return EVAL_BODY_INCLUDE;
	}

	@Override
	public int doEndTag() throws JspException {
		crosstabInfo.setHeader(header);
		reportTag.addCrosstabInfo(crosstabInfo);
		return SKIP_BODY;
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public CrosstabInfo getCrosstabInfo() {
		return crosstabInfo;
	}

	public void setCrosstabInfo(CrosstabInfo crosstabInfo) {
		this.crosstabInfo = crosstabInfo;
	}

	public void addColumnGroupInfo(ColumnGroupInfo columnGroupInfo) {
		crosstabInfo.addColumnGroupInfo(columnGroupInfo);
	}

	public void addRowGroupInfo(RowGroupInfo rowGroupInfo) {
		crosstabInfo.addRowGroupInfo(rowGroupInfo);
	}

	public void addCellInfo(CellInfo cellInfo) {
		crosstabInfo.addCellInfo(cellInfo);
	}

	public void addMeasureInfo(MeasureInfo measureInfo) {
		crosstabInfo.addMeasureInfo(measureInfo);
	}

	public void addNoDataCellInfo(NoDataCellInfo noDataCellInfo) {
		crosstabInfo.addOnDataCell(noDataCellInfo);
	}
}
